Crop

类似于slice(张量切片)。不过只支持四维。

输入:
  • input - 输入数据地址。

  • in_shape - 输入张量形状。

  • out_shape - 输出张量形状。

  • type_size - 输入和输出张量数据类型的长度。

  • offset - 每一维度裁剪开始的偏移量

  • axis - 裁剪开始的维度

  • core_mask - 核掩码。

输出:
  • output - 输出地址。

支持平台:

FT78NE MT7004

备注

  • FT78NE 支持int8, fp32

  • MT7004 支持fp16, fp32

共享/私有存储版本:

void anytype_crop_anycore(void *input, void *output, int *in_shape, int *out_shape, int type_size, int *offset, int axis, int core_mask)

各种数据类型、私有及共享空间版本均使用该函数。对于不同数据类型,改变type_size参数即可。

C调用示例:

 1void TestCropSMCFp32(int* in_shape, int* out_shape, int axis, int* offset_, int core_mask) {
 2    int core_id = get_core_id();
 3    int logic_core_id = GetLogicCoreId(core_mask, core_id);
 4    int core_num = GetCoreNum(core_mask);
 5    float* input = (float*)0x88000000; // 测试私有空间时地址设置在私有空间内即可
 6    float* output = (float*)0x98000000;
 7    int* input_shape = (int*)0xA8000000;
 8    int* output_shape = (int*)0xA8200000;
 9    int type_size = sizeof(float);
10    int* offset = (int*)0xA8410000;
11    if (logic_core_id == 0) {
12        memcpy(offset, offset_, sizeof(int) * (4 - axis));
13        memcpy(input_shape, in_shape, sizeof(int) * 4);
14        memcpy(output_shape, out_shape, sizeof(int) * 4);
15    }
16    sys_bar(0, core_num); // 初始化参数完成后进行同步
17    anytype_crop_anycore(input, output, in_shape, out_shape, type_size, offset, axis, core_mask);
18}
19
20void main(){
21    int in_shape[4] = {2, 3, 3, 5};
22    int out_shape[4] = {2, 2, 2, 5};
23    int axis = 1;
24    int offset[3] = {1, 1, 0};
25    int core_mask = 0b1111; // 测试单核时核掩码设置为0b0001即可
26    TestCropSMCFp32(in_shape, out_shape, axis, offset, core_mask);
27}